﻿using System;
using System.Collections;
using System.Windows.Forms;
using System.Xml;
using HYElectricCommon;

namespace HYRElectric.WirePlace
{
	internal class Common
	{
		public static void GetSharedParameters(ComboBox cmb, string type, string name, string value)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(AssistFunc.GetAppRootPath() + "\\Data\\HYSharedParameters_value.xml");
			foreach (object obj in xmlDocument.DocumentElement.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Name == type)
				{
					IEnumerator enumerator2 = xmlNode.ChildNodes.GetEnumerator();
					{
						while (enumerator2.MoveNext())
						{
							object obj2 = enumerator2.Current;
							XmlNode xmlNode2 = (XmlNode)obj2;
							if (xmlNode2.Name == name)
							{
								IEnumerator enumerator3 = xmlNode2.ChildNodes.GetEnumerator();
								{
									while (enumerator3.MoveNext())
									{
										object obj3 = enumerator3.Current;
										XmlNode xmlNode3 = (XmlNode)obj3;
										if (xmlNode3.Name == value)
										{
											cmb.Items.Add(xmlNode3.InnerText);
										}
									}
									continue;
								}
							}
							if (xmlNode2.Name == name)
							{
								foreach (object obj4 in xmlNode2.ChildNodes)
								{
									XmlNode xmlNode4 = (XmlNode)obj4;
									if (xmlNode4.Name == value)
									{
										cmb.Items.Add(xmlNode4.InnerText);
									}
								}
							}
						}
						continue;
					}
				}
				if (xmlNode.Name == type)
				{
					foreach (object obj5 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode5 = (XmlNode)obj5;
						if (xmlNode5.Name == name)
						{
							foreach (object obj6 in xmlNode5.ChildNodes)
							{
								XmlNode xmlNode6 = (XmlNode)obj6;
								if (xmlNode6.Name == value)
								{
									cmb.Items.Add(xmlNode6.InnerText);
								}
							}
						}
					}
				}
			}
		}

		public static void IsDouble(KeyPressEventArgs e, Control ctl)
		{
			TextBox textBox = ctl as TextBox;
			if (textBox != null)
			{
				if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b' && e.KeyChar != '\r' && e.KeyChar != '-' && e.KeyChar != '.')
				{
					e.Handled = true;
				}
				if (e.KeyChar == '-' && (textBox.SelectionStart != 0 || textBox.Text.IndexOf("-") >= 0))
				{
					e.Handled = true;
				}
				if (e.KeyChar == '.' && textBox.Text.IndexOf(".") >= 0)
				{
					e.Handled = true;
				}
			}
		}

		public static void IsPlusDouble(KeyPressEventArgs e, string txt)
		{
			if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b' && e.KeyChar != '\r' && e.KeyChar != '.')
			{
				e.Handled = true;
			}
			if (e.KeyChar == '.' && txt.IndexOf(".") >= 0)
			{
				e.Handled = true;
			}
		}

		public static bool CheckValue(TextBox txt, string msg)
		{
			double num = 0.0;
			if (string.IsNullOrEmpty(txt.Text))
			{
				MessageBox.Show(msg + "不能为空。", "盈建科提示");
				txt.Focus();
				return false;
			}
			if (!double.TryParse(txt.Text, out num))
			{
				MessageBox.Show(msg + "输入的不合法，请重新输入。", "盈建科提示");
				txt.Focus();
				return false;
			}
			return true;
		}
	}
}
